package com.mz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mz.common.dto.PaginationVo;
import com.mz.common.dto.R;
import com.mz.common.utils.PageDataHandlerUtils;
import com.mz.entity.UmsPermissionInfo;
import com.mz.entity.vo.UmsPermissionInfoQuery;
import com.mz.service.UmsPermissionInfoService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * (UmsPermissionInfo)表控制层
 *
 * @author makejava
 * @since 2023-12-13 13:38:35
 */
@RestController
@RequestMapping("/umsPermissionInfo")
public class UmsPermissionInfoController  {
    /**
     * 服务对象
     */
    @Resource
    private UmsPermissionInfoService umsPermissionInfoService;

    /**
     * 分页查询所有数据
     * @return 所有数据
     */
    @GetMapping("/pagination")
    public R getPermissionPagination(PaginationVo paginationVo, UmsPermissionInfoQuery umsPermissionInfoQuery) throws Exception {
        IPage page = umsPermissionInfoService.getPermissionPagination( paginationVo, umsPermissionInfoQuery );
        return PageDataHandlerUtils.toR(page);
    }


    /**
     * 获取权限树
     * */
    @GetMapping("/list")
    public R getPermissionAllList() throws Exception {
        List<UmsPermissionInfo> dataList =  umsPermissionInfoService.getPermissionAllList();
        return R.ok(dataList);
    }


    /**
     * 新增数据
     *
     * @param umsPermissionInfo 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R addPermission(@RequestBody UmsPermissionInfo umsPermissionInfo) throws Exception {
        umsPermissionInfoService.addPermission( umsPermissionInfo );
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @PostMapping("/remove")
    public R removePermission(@RequestBody List<Long> idList) throws Exception {
        umsPermissionInfoService.removePermission(idList);
        return R.ok();
    }
}

